//
//  SEPrescriptionOrderListCell.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/16.
//

import UIKit

enum SEPrescriptionOrderListCellActionType {
    case cancel
    case pay
    case detail
    case logistics
}

protocol SEPrescriptionOrderListCellDelegate: NSObjectProtocol {
    func prescriptionOrderListCellBtnAction(type: SEPrescriptionOrderListCellActionType, indexPath: IndexPath)
}

class SEPrescriptionOrderListCell: UITableViewCell {

    static let className = "SEPrescriptionOrderListCell"
    static let reuseId = className

    @IBOutlet weak var doctorNameLabel: UILabel!
    @IBOutlet weak var jobTitleLabel: UILabel!
    @IBOutlet weak var statusLabel: UILabel!
    @IBOutlet weak var resultLabel: UILabel!
    @IBOutlet weak var drugNamesLabel: UILabel!
    @IBOutlet weak var patientNameLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!

    @IBOutlet weak var stackBgView: UIView! {
        didSet{
            stackBgView.layer.cornerRadius = 4
            stackBgView.layer.borderWidth = 1
            stackBgView.layer.borderColor = Asset.main.color.withAlphaComponent(0.15).cgColor
            stackBgView.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var cancelBtn: UIButton! {
        didSet {
            cancelBtn.layer.cornerRadius = cancelBtn.frame.size.height / 2.0
            cancelBtn.layer.borderWidth = 1
            cancelBtn.layer.borderColor = Asset.textGrayLightest.color.cgColor
            cancelBtn.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var payBtn: UIButton! {
        didSet {
            payBtn.layer.cornerRadius = payBtn.frame.size.height / 2.0
            payBtn.layer.borderWidth = 1
            payBtn.layer.borderColor = Asset.main.color.cgColor
            payBtn.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var logisticsBtn: UIButton! {
        didSet {
            logisticsBtn.layer.cornerRadius = logisticsBtn.frame.size.height / 2.0
            logisticsBtn.layer.borderWidth = 1
            logisticsBtn.layer.borderColor = Asset.main.color.cgColor
            logisticsBtn.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var detailBtn: UIButton! {
        didSet {
            detailBtn.layer.cornerRadius = detailBtn.frame.size.height / 2.0
            detailBtn.layer.borderWidth = 1
            detailBtn.layer.borderColor = Asset.main.color.cgColor
            detailBtn.layer.masksToBounds = true
        }
    }

    @IBAction func cancelBtnAction(_ sender: UIButton) {
        delegate?.prescriptionOrderListCellBtnAction(type: .cancel, indexPath: indexPath)
    }

    @IBAction func payBtnAction(_ sender: UIButton) {
        delegate?.prescriptionOrderListCellBtnAction(type: .pay, indexPath: indexPath)
    }

    @IBAction func logsiticsBtnAction(_ sender: UIButton) {
        delegate?.prescriptionOrderListCellBtnAction(type: .logistics, indexPath: indexPath)
    }

    @IBAction func detailBtnAction(_ sender: UIButton) {
        delegate?.prescriptionOrderListCellBtnAction(type: .detail, indexPath: indexPath)
    }

    weak var delegate: SEPrescriptionOrderListCellDelegate?
    private var indexPath = IndexPath(row: 0, section: 0)

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func updateData(_ viewModel: SEPrescriptionOrderDetailViewModel, indexPath: IndexPath) {
        self.indexPath = indexPath
        doctorNameLabel.text = viewModel.model.doctor
        jobTitleLabel.text = viewModel.model.jobTitle
//        statusLabel.text = viewModel.model.orderStatus.title
        statusLabel.isHidden = true
        resultLabel.text = viewModel.mainDiagnose
        drugNamesLabel.text = viewModel.model.drugNames
        patientNameLabel.text = "就诊人: \(viewModel.model.patientName)"
        timeLabel.text = viewModel.model.createTime
        payBtn.isHidden = viewModel.model.orderStatus.isHiddenPay
        cancelBtn.isHidden = viewModel.model.orderStatus.isHiddenCancel
        detailBtn.isHidden = viewModel.model.orderStatus.isHiddenDetail
        logisticsBtn.isHidden = viewModel.model.orderStatus.isHiddenLogstics
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
